package com.example.behavior.controller;

import com.example.behavior.service.BehaviorService;
import com.example.common.util.R;
import com.example.model.behavior.dto.LikesBehaviorDto;
import com.example.model.behavior.dto.ReadBehaviorDto;
import com.example.model.behavior.dto.UnLikesBehaviorDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/")
@Tag(name = "行为处理管理")
public class BehaviorController {
    @Autowired
    private BehaviorService behaviorService;

    @PostMapping(value = "/behavior/behavior_likes")
    @Operation(summary = "点赞行为")
    public R behaviorLikes(@RequestBody LikesBehaviorDto likesBehaviorDto) {
        boolean flag = behaviorService.like(likesBehaviorDto);
        if (flag) {
            return R.ok("点赞行为成功");
        } else {
            return R.error("点赞行为失败");
        }
    }

    @PostMapping(value = "/behavior/behavior_unLikes")
    @Operation(summary = "取消点赞行为")
    public R behaviorUnLikes(@RequestBody UnLikesBehaviorDto unLikesBehaviorDto) {
        boolean flag = behaviorService.unLike(unLikesBehaviorDto);
        if (flag) {
            return R.ok("取消点赞行为成功");
        } else {
            return R.error("取消点赞行为失败");
        }
    }

    @PostMapping(value = "/behavior/behavior_read")
    @Operation(summary = "阅读行为")
    public R behaviorRead(@RequestBody ReadBehaviorDto readBehaviorDto) {
        boolean flag = behaviorService.read(readBehaviorDto);
        if (flag) {
            return R.ok("阅读行为成功");
        } else {
            return R.error("阅读行为失败");
        }
    }
}
